﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace GC_MU.Core.Extensions.IO
{
	public static class DirectoryInfoEx
	{
		public static IEnumerable<string> GetFilesByExtensions(this DirectoryInfo directoryInfo,
			IEnumerable<string> fileExtensions)
		{
			if (directoryInfo == null) return null;

			var files = directoryInfo.GetFiles();
			var extensions = (fileExtensions ?? new List<string>()).ToList();

			return extensions.Any()
				? files
					.Where(f => extensions.Contains(f.Extension, StringComparer.OrdinalIgnoreCase))
					.Select(f => f.Name)
					.ToList()
				: files.Select(f => f.Name).ToList();
		}
	}
}
